import { getCategoryApi } from "@/api/category";
import { onBeforeRouteUpdate } from "vue-router";
import { onMounted, ref } from "vue";
import { useRoute } from "vue-router";
export const useCategory = () => {
  const categoryData = ref({});
  const route = useRoute();
  const getCategory = async (id = route.params.id) => {
    const res = await getCategoryApi(id);
    categoryData.value = res.result;
  };
  onBeforeRouteUpdate((to, from) => {
    getCategory(to.params.id);
  });
  onMounted(() => {
    getCategory();
  });
  return { categoryData };
};
